package com.goodving.guli.fragment;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.bt.DimPanelFragment;
import com.goodving.guli.bt.Utils;
import com.goodving.guli.bt.profile.scale.C3515h;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.ui.PickAdapter;
import com.goodving.guli.bt.utils.WeightUtil;
import com.goodving.guli.view.C3657a;
import com.goodving.guli.view.C4220a;

import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Date;

import kankan.wheel.widget.OnWheelChangedListener;
import kankan.wheel.widget.OnWheelScrollListener;
import kankan.wheel.widget.WheelView;

/**
 * Created by john on 2015/12/25.
 */
public class SettingDateFragment extends DimPanelFragment { // SettingDateFragment
    public static final int f11535a = -11;
    public static final int f11536b = -10;
    private static final String f11537j = "SettingDateFragment";
    private WheelView f11538c;
    private WheelView f11539d;
    private WheelView f11540e;
    private WheelView f11541f;
    private WheelView f11542g;
    private View f11543h;
    private TextView f11544i;
    private int f11545k;
    private int f11546l;
    private int f11547m;
    private int f11548n;
    private int f11549o;
    private int f11550p;
    private PickAdapter f11551q;
    private boolean f11552r;
    private Calendar f11553s;
    private DecimalFormat f11554t;
    private C1970E f11555u;
    private C1971F f11556v;

    public interface C1970E {
        void m15552a(int i, int i2, int i3, int i4, int i5);
    }

    public interface C1971F {
        void m15553a();
    }

    public SettingDateFragment() {
        this.f11550p = 0;
        this.f11552r = false;
    }

    private long m15911a(int i, int i2, int i3, int i4, int i5, int i6) {
        GuliLog.tracePrintInfo(f11537j, "year " + i + " month " + i2 + " day " + i3 + " hour " + i4 + " minute " + i5 + " second " + i6);
        this.f11553s.clear();
        this.f11553s.set(i, i2 - 1, i3, i4, i5, i6);
        long timeInMillis = this.f11553s.getTimeInMillis();
        GuliLog.tracePrintInfo(f11537j, "time in mill " + timeInMillis);
        GuliLog.tracePrintInfo(f11537j, "time in str " + new Date(timeInMillis).toLocaleString());
        return timeInMillis;
    }

    private void m15913a() {
        if (!isAdded()) {
            return;
        }
        if (Utils.m8103x(getActivity().getApplicationContext())) {
            this.f11544i.setText(getString(R.string.date) + "\t\t" + this.f11547m + "-" + this.f11554t.format((long) this.f11545k) + "-" + this.f11554t.format((long) this.f11546l) + " " + this.f11554t.format((long) this.f11548n) + C4220a.ci + this.f11554t.format((long) this.f11549o));
        } else if (this.f11548n >= 12) {
            this.f11544i.setText(getString(R.string.date) + "\t\t" + this.f11547m + "-" + this.f11554t.format((long) this.f11545k) + "-" + this.f11554t.format((long) this.f11546l) + " " + this.f11554t.format((long) (this.f11548n - 12)) + C4220a.ci + this.f11554t.format((long) this.f11549o) + " " + getString(R.string.pm));
        } else {
            this.f11544i.setText(getString(R.string.date) + "\t\t" + this.f11547m + "-" + this.f11554t.format((long) this.f11545k) + "-" + this.f11554t.format((long) this.f11546l) + " " + this.f11554t.format((long) this.f11548n) + C4220a.ci + this.f11554t.format((long) this.f11549o) + " " + getString(R.string.am));
        }
    }

    static /* synthetic */ int m15918d(SettingDateFragment c2048t, int i) {
        int i2 = c2048t.f11548n + i;
        c2048t.f11548n = i2;
        return i2;
    }

    static /* synthetic */ int m15925g(SettingDateFragment c2048t, int i) {
        int i2 = c2048t.f11548n - i;
        c2048t.f11548n = i2;
        return i2;
    }

    public int m15932a(int i, int i2) {
        Calendar instance = Calendar.getInstance();
        instance.set(Calendar.YEAR, i);
        instance.set(Calendar.MONTH, i2 - 1);
        instance.set(Calendar.DATE, 1);
        return instance.getActualMaximum(Calendar.DATE);
    }

    public void m15933a(C1970E c1970e) {
        this.f11555u = c1970e;
    }

    public void m15934a(C1971F c1971f) {
        this.f11556v = c1971f;
    }

    protected int inflateLayout() {
        return R.layout.fragment_setting_date;
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.f11553s = Calendar.getInstance();
    }

    class C2049u implements OnWheelChangedListener { // C1824c
        final /* synthetic */ SettingDateFragment f11557a;

        C2049u(SettingDateFragment c2048t) {
            this.f11557a = c2048t;
        }

        public void onChanged(WheelView wheelView, int i, int i2) {
            if (this.f11557a.isAdded()) {
                this.f11557a.f11539d.setVisibleItems(5).setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(this.f11557a.getString(R.string.day_ri), (float) WeightUtil.f11306h).setViewAdapter(new PickAdapter(this.f11557a.getActivity(), 1, this.f11557a.m15932a(this.f11557a.f11547m, i2 + 1), this.f11557a.f11539d, this.f11557a.getResources().getColor(R.color.highlight), this.f11557a.getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1)).setCyclic(true); // m26795a
                GuliLog.tracePrintInfo("SettingDateFragment", "cur day " + this.f11557a.f11546l + " max day " + this.f11557a.m15932a(this.f11557a.f11547m, i2 + 1));
                if (this.f11557a.f11546l > this.f11557a.m15932a(this.f11557a.f11547m, i2 + 1)) {
                    this.f11557a.f11539d.setCurrentItem(this.f11557a.m15932a(this.f11557a.f11547m, i2 + 1) - 1);
                } else {
                    this.f11557a.f11539d.setCurrentItem(this.f11557a.f11546l - 1);
                }
                GuliLog.tracePrintInfo("SettingDateFragment", "oldValue " + i + " newValue " + i2);
                this.f11557a.f11545k = i2 + 1;
                this.f11557a.m15913a();
            }
        }
    }

    class C2053y implements OnWheelScrollListener {
        final /* synthetic */ SettingDateFragment f11561a;

        C2053y(SettingDateFragment c2048t) {
            this.f11561a = c2048t;
        }

        public void onScrollingStarted(WheelView wheelView) {
        }

        public void onScrollingFinished(WheelView wheelView) {
            int i = Calendar.getInstance().get(Calendar.MONTH) + 1;
            int i2 = Calendar.getInstance().get(Calendar.DATE);
            int f = wheelView.getRealCurrentItem() + 1;
            long a = this.f11561a.m15911a(this.f11561a.f11547m, f, this.f11561a.f11546l, this.f11561a.f11548n, this.f11561a.f11549o, 0);
            if (a == 0 || a > System.currentTimeMillis()) {
                this.f11561a.f11538c.scroll(12 - (f - i), (int) C3515h.f17660E);
                if (this.f11561a.f11546l > i2) {
                    this.f11561a.f11539d.scroll(this.f11561a.m15932a(this.f11561a.f11547m, i) - (this.f11561a.f11546l - i2), (int) C3515h.f17660E);
                }
            }
        }
    }

    class C2051w implements OnWheelChangedListener {
        final /* synthetic */ SettingDateFragment f11559a;

        C2051w(SettingDateFragment c2048t) {
            this.f11559a = c2048t;
        }

        public void onChanged(WheelView wheelView, int i, int i2) {
            int a = this.f11559a.m15932a(this.f11559a.f11547m, this.f11559a.f11545k);
            int i3 = (i % a) + 1;
            this.f11559a.f11546l = (i2 % a) + 1;
            this.f11559a.m15913a();
        }
    }


    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View onCreateView = super.onCreateView(layoutInflater, viewGroup, bundle);
        this.f11554t = new DecimalFormat("00");
        this.f11538c = (WheelView) onCreateView.findViewById(R.id.setting_birth_wheel_month);
        this.f11539d = (WheelView) onCreateView.findViewById(R.id.setting_birth_wheel_day);
        this.f11540e = (WheelView) onCreateView.findViewById(R.id.setting_birth_wheel_hour);
        this.f11541f = (WheelView) onCreateView.findViewById(R.id.setting_birth_wheel_minute);
        this.f11542g = (WheelView) onCreateView.findViewById(R.id.setting_birth_wheel_ampm);
        this.f11543h = onCreateView.findViewById(R.id.wheel_ampm_divider);
        this.f11544i = (TextView) onCreateView.findViewById(R.id.setting_date_title);
        this.f11545k = Calendar.getInstance().get(Calendar.MONTH) + 1;
        this.f11546l = Calendar.getInstance().get(Calendar.DATE);
        this.f11547m = Calendar.getInstance().get(Calendar.YEAR);
        this.f11548n = new Date().getHours();
        this.f11549o = new Date().getMinutes();
        this.f11552r = Utils.m8103x(getActivity().getApplicationContext());
        if (!this.f11552r) {
            if (this.f11548n >= 12) {
                this.f11550p = 1;
            } else {
                this.f11550p = 0;
            }
        }
        m15913a();
        PickAdapter dmVar = new PickAdapter(getActivity(), 1, 12, this.f11538c, getResources().getColor(R.color.highlight), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1);
        PickAdapter dmVar2 = new PickAdapter(getActivity(), 1, m15932a(this.f11547m, this.f11545k), this.f11539d, getResources().getColor(R.color.highlight), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1);
        PickAdapter dmVar3 = new PickAdapter(getActivity(), 0, 59, this.f11541f, getResources().getColor(R.color.highlight), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1);
        PickAdapter dmVar4 = new PickAdapter(getActivity(), f11535a, f11536b, this.f11542g, getResources().getColor(R.color.bg_color_blue), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 18, 15, 21, 1);
        dmVar4.m14688a(PickAdapter.f9987c);
        dmVar4.m14686a(17);
        if (Utils.m8103x(getActivity().getApplicationContext())) {
            this.f11543h.setVisibility(View.GONE);
            this.f11542g.setVisibility(View.GONE);
            this.f11551q = new PickAdapter(getActivity(), 0, 23, this.f11540e, getResources().getColor(R.color.highlight), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1);
        } else {
            this.f11543h.setVisibility(View.VISIBLE);
            this.f11542g.setVisibility(View.VISIBLE);
            this.f11551q = new PickAdapter(getActivity(), 0, 11, this.f11540e, getResources().getColor(R.color.highlight), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1);
        }
        this.f11538c.setVisibleItems(5).setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(getString(R.string.month), (float) WeightUtil.f11306h).setViewAdapter(dmVar).setCurrentItem(this.f11545k - 1).setCyclic(true);
        this.f11539d.setVisibleItems(5).setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(getString(R.string.day_ri), (float) WeightUtil.f11306h).setViewAdapter(dmVar2).setCurrentItem(this.f11546l - 1).setCyclic(true);
        this.f11541f.setVisibleItems(5).setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(getString(R.string.minute), (float) WeightUtil.f11306h).setViewAdapter(dmVar3).setCurrentItem(this.f11549o).setCyclic(true);
        this.f11542g.setVisibleItems(2).setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(C3657a.f18328f, (float) WeightUtil.f11306h).setViewAdapter(dmVar4).setCurrentItem(0).setCyclic(false);
        if (Utils.m8103x(getActivity().getApplicationContext())) {
            this.f11540e.setVisibleItems(5).setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(getString(R.string.hour_1), (float) WeightUtil.f11306h).setViewAdapter(this.f11551q).setCurrentItem(this.f11548n).setCyclic(true);
        } else if (this.f11548n >= 12) {
            this.f11540e.setVisibleItems(5).setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(getString(R.string.hour_1), (float) WeightUtil.f11306h).setViewAdapter(this.f11551q).setCurrentItem(this.f11548n - 12).setCyclic(true);
            this.f11542g.setCurrentItem(1);
        } else {
            this.f11540e.setVisibleItems(5).setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(getString(R.string.hour_1), (float) WeightUtil.f11306h).setViewAdapter(this.f11551q).setCurrentItem(this.f11548n).setCyclic(true);
            this.f11542g.setCurrentItem(0);
        }
        this.f11538c.addChangingListener(new C2049u(this)); // m26792a
        this.f11539d.addChangingListener(new C2051w(this));
        this.f11540e.addChangingListener(new C2052x(this));
        this.f11538c.addScrollingListener(new C2053y(this));
        this.f11539d.addScrollingListener(new C2054z(this));
        this.f11540e.addScrollingListener(new C1966A(this));
        this.f11541f.addScrollingListener(new C1967B(this));
        this.f11541f.addChangingListener(new C1968C(this));
        this.f11542g.addChangingListener(new C1969D(this));
        this.f11542g.addScrollingListener(new C2050v(this));
        return onCreateView;
    }

    class C2050v implements OnWheelScrollListener {
        final /* synthetic */ SettingDateFragment f11558a;

        C2050v(SettingDateFragment c2048t) {
            this.f11558a = c2048t;
        }

        public void onScrollingStarted(WheelView wheelView) {
        }

        public void onScrollingFinished(WheelView wheelView) {
            long a = this.f11558a.m15911a(this.f11558a.f11547m, this.f11558a.f11545k, this.f11558a.f11546l, this.f11558a.f11548n, this.f11558a.f11549o, 0);
            GuliLog.tracePrintInfo("SettingDateFragment", "time in str " + new Date(a).toLocaleString());
            if ((a == 0 || a > System.currentTimeMillis()) && wheelView.getRealCurrentItem() == 1) {
                this.f11558a.f11542g.scroll(-1, (int) C3515h.f17660E);
            }
        }
    }

    class C1967B implements OnWheelScrollListener {
        final /* synthetic */ SettingDateFragment f11064a;

        C1967B(SettingDateFragment c2048t) {
            this.f11064a = c2048t;
        }

        public void onScrollingStarted(WheelView wheelView) {
        }

        public void onScrollingFinished(WheelView wheelView) {
            boolean z = false;
            int i = Calendar.getInstance().get(Calendar.MINUTE);
            int f = wheelView.getRealCurrentItem();
            GuliLog.tracePrintInfo("SettingDateFragment", "nowMinute " + i + " curMinute " + f);
            long a = this.f11064a.m15911a(this.f11064a.f11547m, this.f11064a.f11545k, this.f11064a.f11546l, this.f11064a.f11548n, f, 0);
            String str = "SettingDateFragment";
            StringBuilder stringBuilder = new StringBuilder();
            if (a == 0 || a > System.currentTimeMillis()) {
                z = true;
            }
            GuliLog.tracePrintInfo(str, stringBuilder.append(z).append("   l ").append(a).append(" ").append(new Date(a).toLocaleString()).append(" System.cur ").append(System.currentTimeMillis()).append(" ").append(new Date(System.currentTimeMillis()).toLocaleString()).toString());
            if (a == 0 || a > System.currentTimeMillis()) {
                this.f11064a.f11541f.scroll(60 - (f - i), (int) C3515h.f17660E); // m26799b
            }
        }
    }

    class C1968C implements OnWheelChangedListener {
        final /* synthetic */ SettingDateFragment f11103a;

        C1968C(SettingDateFragment c2048t) {
            this.f11103a = c2048t;
        }

        public void onChanged(WheelView wheelView, int i, int i2) {
            this.f11103a.f11549o = i2;
            this.f11103a.m15913a();
        }
    }

    class C1969D implements OnWheelChangedListener {
        final /* synthetic */ SettingDateFragment f11104a;

        C1969D(SettingDateFragment c2048t) {
            this.f11104a = c2048t;
        }

        public void onChanged(WheelView wheelView, int i, int i2) {
            this.f11104a.f11550p = i2;
            if (i == 0 && this.f11104a.f11550p == 1) {
                SettingDateFragment.m15918d(this.f11104a, 12);
            } else if (i == 1 && i2 == 0) {
                SettingDateFragment.m15925g(this.f11104a, 12);
            }
            this.f11104a.m15913a();
        }
    }

    class C1966A implements OnWheelScrollListener {
        final /* synthetic */ SettingDateFragment f11063a;

        C1966A(SettingDateFragment c2048t) {
            this.f11063a = c2048t;
        }

        public void onScrollingStarted(WheelView wheelView) {
        }

        public void onScrollingFinished(WheelView wheelView) {
            int i = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
            int f = wheelView.getRealCurrentItem();
            GuliLog.tracePrintInfo("SettingDateFragment", "nowHour " + i + " curHour " + f);
            long a = this.f11063a.m15911a(this.f11063a.f11547m, this.f11063a.f11545k, this.f11063a.f11546l, this.f11063a.f11550p == 1 ? f + 12 : f, this.f11063a.f11549o, 0);
            if (a != 0 && a <= System.currentTimeMillis()) {
                return;
            }
            if (this.f11063a.f11552r) {
                this.f11063a.f11540e.scroll(24 - (f - i), (int) C3515h.f17660E);
            } else {
                this.f11063a.f11540e.scroll(12 - (f - i), (int) C3515h.f17660E);
            }
        }
    }


    class C2054z implements OnWheelScrollListener {
        final /* synthetic */ SettingDateFragment f11562a;

        C2054z(SettingDateFragment c2048t) {
            this.f11562a = c2048t;
        }

        public void onScrollingStarted(WheelView wheelView) {
        }

        public void onScrollingFinished(WheelView wheelView) {
            int i = Calendar.getInstance().get(Calendar.DATE);
            int f = wheelView.getRealCurrentItem() + 1;
            long a = this.f11562a.m15911a(this.f11562a.f11547m, this.f11562a.f11545k, f, this.f11562a.f11548n, this.f11562a.f11549o, 0);
            if (a == 0 || a > System.currentTimeMillis()) {
                this.f11562a.f11539d.scroll(this.f11562a.m15932a(this.f11562a.f11547m, this.f11562a.f11545k) - (f - i), (int) C3515h.f17660E);
            }
        }
    }

    class C2052x implements OnWheelChangedListener {
        final /* synthetic */ SettingDateFragment f11560a;

        C2052x(SettingDateFragment c2048t) {
            this.f11560a = c2048t;
        }

        public void onChanged(WheelView wheelView, int i, int i2) {
            this.f11560a.f11548n = i2;
            if (this.f11560a.f11550p == 1) {
                SettingDateFragment.m15918d(this.f11560a, 12);
            }
            this.f11560a.m15913a();
        }
    }

    public void onDismiss(DialogInterface dialogInterface) {
        super.onDismiss(dialogInterface);
        if (this.f11556v != null) {
            this.f11556v.m15553a();
        }
    }

    protected void onRightButtonClicked() {
        if (this.f11555u != null) {
            long a = m15911a(this.f11547m, this.f11545k, this.f11546l, this.f11548n, this.f11549o, 0);
            if (a != 0 && a <= System.currentTimeMillis()) {
                this.f11555u.m15552a(this.f11547m, this.f11545k, this.f11546l, this.f11548n, this.f11549o);
            } else {
                return;
            }
        }
        dismiss();
    }
}
